﻿#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class MeshToDouble : MonoBehaviour
{
    // Start is called before the first frame update
    public void Create()
    {
        var mf = GetComponent<MeshFilter>();
        if(mf!=null)
        {
            var tris = mf.sharedMesh.triangles;
            if(tris!=null)
            {
                List<int> tmp = new List<int>();
                tmp.AddRange(tris);
                int len = tris.Length / 3;
                for(int i=0;i<len;i++)
                {
                    int s = i * 3;
                    tmp.Add(tris[s]);
                    tmp.Add(tris[s+2]);
                    tmp.Add(tris[s+1]);
                }
                mf.sharedMesh.triangles = tmp.ToArray();
            }
        }
    }


}

[CustomEditor(typeof(MeshToDouble))]
public class MeshToDoubleEditor:Editor
{
    public override void OnInspectorGUI()
    {
        if(GUILayout.Button("Create"))
        {
            var mt= target as MeshToDouble;
            if (mt != null)
                mt.Create();
        }
    }
}
#endif
